import base
from video import get_image, get_focused_area_list
import math
import numpy as np




def get_focused_psnr(im_path, gt_path, mode="RGB", crop=0):
    img, gt = get_image(im_path, gt_path, crop=crop)
    img_list, gt_list = get_focused_area_list(img, gt)
    psnr_list = []
    for one_img, one_gt in zip(img_list, gt_list):
        one_psnr = base.psnr(one_img, one_gt, mode=mode)
        psnr_list.append(one_psnr)
    return np.mean(psnr_list)


def get_psnr(im_path, gt_path, mode="RGB", crop=0):
    img, gt = get_image(im_path, gt_path, crop=crop)
    return base.psnr(img, gt, mode=mode)


def get_ssim(im_path, gt_path, mode="RGB", crop=0):
    img, gt = get_image(im_path, gt_path, crop=crop)
    return base.ssim(img, gt, mode=mode)


def get_ws_psnr(im_path, gt_path, mode="RGB", crop=0):
    img, gt = get_image(im_path, gt_path, crop=crop)
    return base.psnr(img, gt, mode=mode)


def get_ws_ssim(im_path, gt_path, mode="RGB", crop=0):
    img, gt = get_image(im_path, gt_path, crop=crop)
    return base.ssim(img, gt, mode=mode)


def template_matching(target_path="", template_path="", other_dir=""):
    base.template_matching(target_name=target_path,
                           template_name=template_path,
                           other_dir="")
